home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / tnos / tnos100s / slhcdump.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-30  |  2.7 KB  |  125 lines

  1. #include <stdio.h>
  2. #include "global.h"
  3. #include "mbuf.h"
  4. #include "internet.h"
  5. #include "ip.h"
  6. #include "slhc.h"
  7. #include "trace.h"
  8.  
  9. #ifdef TNOS_68K
  10. #define fprintf traceprintf
  11. #endif
  12.  
  13. static int16 decodeint __ARGS((struct mbuf **bpp));
  14.  
  15. static int16
  16. decodeint(bpp)
  17. struct mbuf **bpp;
  18. {
  19.     char tmpbuf[2];
  20.  
  21.     pullup(bpp,tmpbuf,1);
  22.     if (tmpbuf[0] == 0)
  23.         pullup(bpp,tmpbuf,2);
  24.     else {
  25.          tmpbuf[1] = tmpbuf[0];
  26.         tmpbuf[0] = 0;
  27.     }
  28.     return(get16(tmpbuf));
  29. }
  30.  
  31. void
  32. vjcomp_dump(fp,bpp,unused)
  33. FILE *fp;
  34. struct mbuf **bpp;
  35. int unused;
  36. {
  37.     char changes;
  38.     char tmpbuf[2];
  39.  
  40.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  41.         return;    
  42.  
  43.     /* Dump compressed TCP/IP header */
  44.     changes = pullchar(bpp);
  45.     fprintf(fp,"\tchanges: 0x%02x",uchar(changes));
  46.     if (changes & NEW_C) {
  47.         pullup(bpp,tmpbuf,1);
  48.         fprintf(fp,"   connection: 0x%02x",uchar(tmpbuf[0]));
  49.     }
  50.     pullup(bpp,tmpbuf,2);
  51.     fprintf(fp,"   TCP checksum: 0x%04x",get16(tmpbuf));
  52.  
  53.     if (changes & TCP_PUSH_BIT)
  54.         fprintf(fp,"   PUSH");
  55.     fprintf(fp,"\n");
  56.  
  57.     switch (changes & SPECIALS_MASK) {
  58.     case SPECIAL_I:
  59.         fprintf(fp,"\tdelta ACK and delta SEQ implied by length of data\n");
  60.         break;
  61.  
  62.     case SPECIAL_D:
  63.         fprintf(fp,"\tdelta SEQ implied by length of data\n");
  64.         break;
  65.  
  66.     default:
  67.         if (changes & NEW_U) {
  68.             fprintf(fp,"\tUrgent pointer: 0x%02x",decodeint(bpp));
  69.         }
  70.         if (changes & NEW_W)
  71.             fprintf(fp,"\tdelta WINDOW: 0x%02x",decodeint(bpp));
  72.         if (changes & NEW_A)
  73.             fprintf(fp,"\tdelta ACK: 0x%02x",decodeint(bpp));
  74.         if (changes & NEW_S)
  75.             fprintf(fp,"\tdelta SEQ: 0x%02x",decodeint(bpp));
  76.         break;
  77.     };
  78.     if (changes & NEW_I) {
  79.         fprintf(fp,"\tdelta ID: 0x%02x\n",decodeint(bpp));
  80.     } else {
  81.         fprintf(fp,"\tincrement ID\n");
  82.     }
  83. }
  84.  
  85.  
  86. /* dump serial line IP packet; may have Van Jacobson TCP header compression */
  87. void
  88. sl_dump(fp,bpp,unused)
  89. FILE *fp;
  90. struct mbuf **bpp;
  91. int unused;
  92. {
  93.     struct mbuf *bp, *tbp;
  94.     unsigned char c;
  95.     int len;
  96.  
  97.     bp = *bpp;
  98.     c = bp->data[0];
  99.     if (c & SL_TYPE_COMPRESSED_TCP) {
  100.         fprintf(fp,"serial line VJ Compressed TCP: len %3u\n",
  101.             len_p(*bpp));
  102.         vjcomp_dump(fp,bpp,0);
  103.     } else if ( c >= SL_TYPE_UNCOMPRESSED_TCP ) {
  104.         fprintf(fp,"serial line VJ Uncompressed TCP: len %3u\n",
  105.             len = len_p(bp));
  106.         /* Get our own copy so we can mess with the data */
  107.         if ( (tbp = copy_p(bp, len)) == NULLBUF )
  108.             return;
  109.  
  110.         fprintf(fp,"\tconnection ID = %d\n",
  111.             uchar(tbp->data[9]));    /* FIX THIS! */
  112.         /* Restore the bytes used with Uncompressed TCP */
  113.         tbp->data[0] &= 0x4f;        /* FIX THIS! */
  114.         tbp->data[9] = TCP_PTCL;    /* FIX THIS! */    
  115.         /* Dump contents as a regular IP packet */
  116.         ip_dump(fp,&tbp,1);
  117.         free_p(tbp);
  118.     } else {
  119.         fprintf(fp,"serial line IP: len: %3u\n",len_p(*bpp));
  120.         ip_dump(fp,bpp,1);
  121.     }
  122. }
  123.  
  124.  
  125.